<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <link href="../css/element.css" rel="stylesheet"/>
    <link href="../css/styleindex.css" rel="stylesheet"/>
    <style>
    .el-input__inner{
      border: 0;
      font-size: 1rem;
      text-align: center;
    }.el-input__prefix{
      display: none;
    }
    </style>
</head>
<body style="background:#EFF0F4;">

  <div class="mui-content">
    <div id="vm" class="x-examok" v-cloak>
      <div class="x-header-g" id="header">
        <a class="x-header-arrow" @click="api.closeWin()"></a>
        <div class="x-header-t">经营指导</div>
      </div>
      <!--  -->
      <div class="x-ico-month x-ico-month2">
        <el-date-picker v-model="cardsmonth" type="month" placeholder="选择月" @change="getmonthdata" format="yyyy 年 MM 月" value-format="yyyyMM" :editable="notkey"></el-date-picker>
      </div>
      <!--  -->
      <el-table :data="tabledata" @cell-click="">
        <el-table-column label="指导门店" width="" fixed>
          <template slot-scope="scope">
            {{scope.row.shop_title}}
          </template>
        </el-table-column>
        <el-table-column label="主题" width="">
          <template slot-scope="scope">
            {{scope.row.title}}
          </template>
        </el-table-column>
        <el-table-column label="制定人" width="">
          <template slot-scope="scope">
            <div v-if="scope.row.real_time!=''">{{scope.row.username}}</div>
            <div v-else>无</div>
          </template>
        </el-table-column>
        <!-- <el-table-column label="完善内容" width="">
          <template slot-scope="scope">
            <div v-if="scope.row.patrol_username!=''">{{scope.row.patrol_username}}</div>
            <div v-else>无</div>
          </template>
        </el-table-column> -->
        <el-table-column label="实施效果" width="">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="gotake(scope.row.result_str,scope.row.result_img,scope.row.id)">查看</el-button>
          </template>
        </el-table-column>
        <el-table-column label="操作" width="">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="addfeed('3',scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
      <!--  -->
      <div class="x-pro-gobtn" @click="addfeed('1')" v-show="!isfromindex">添加新指导</div>
      <!--  -->
      <el-dialog title="添加实施效果" :visible.sync="edittoast" width="90%" center="true" close-on-click-modal="false" show-close="false">
        <div class="x-pro-row">
          <div class="x-pro-label">添加文字：</div>
          <div class="x-pro-input">
            <el-input placeholder="请输入" v-model="textvalue" type="textarea" :rows="3"></el-input>
          </div>
        </div>
        <div class="x-pro-row">
          <div class="x-pro-label">添加图片：</div>
          <div class="x-pro-input">
            <el-button type="success" @click="imgPer">添加图片</el-button>
          </div>
        </div>
        <div class="x-pro-himg" :style="{'background-image':'url(' +input4+ ')','background-size':'cover','width':'6rem','height':'6rem','border-radius':'0.4rem','margin-top':'1rem'}" v-if="input4!=''" @click="imagebig = true"></div>
        <span slot="footer" class="dialog-footer">
          <div class="x-pro-gobtn" @click="okgettime" v-show="!isfromindex">提交</div>
        </span>
      </el-dialog>
      <img :src="input4" alt="" width="100%" v-if="imagebig" class="x-img-big" @click="imagebig = false">
    </div>
  </div>

  <script type="text/javascript" src="../script/vue.js"></script>
  <script type="text/javascript" src="../script/element.js"></script>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/base.js"></script>
	<script>
apiready = function () {
    $api.fixStatusBar($api.byId('header'));
    api.addEventListener({
        name: 'addrunback'
    }, function(ret, err) {
        vm.getdata()
    });

    //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
            cardsmonth:'',
            notkey:false,
            tabledata:'',
            isfromindex:false,
            edittoast:false,
            textvalue:'',
            input4:'',
            listid:'',
          imagebig:false

        }
      },
      created:function() {
        var that=this;


      },
      mounted:function(){
        var that=this;
        //当前月份
        var date = new Date();
        var year = date.getFullYear();
        var month = date.getMonth()+1;
        if(month<10){
          month = '' + 0 + month;
        }
        var toMonth = '' + year + month ;
        that.cardsmonth = toMonth;
        that.getdata()

      },
      methods: {
        //实施效果
        gotake:function(con,img,id){
            let that=this;
            that.textvalue = con;
            that.input4 = img;
            that.listid = id;
            that.edittoast = true;
        },
        //
        getdata:function(){
            let that=this;
            api.ajax({
                url:baseurl+'api/guide/contentList',
                methods:'get',
                data:{
                values:{
                        sec: $api.getStorage('apptoken'),
                        date:that.cardsmonth
                    }
                }
            },function(ret,err){
                if(ret){
                api.hideProgress();
                console.log(JSON.stringify(ret));
                if(ret.status == 1){
                    that.tabledata = ret.data.list;
                    
                    
                }else{
                    api.toast({
                        msg: ret.msg,
                        duration: 3000,
                        location: 'bottom'
                    });
                }
                }else{
                api.hideProgress();
                console.log(JSON.stringify(err));
                api.toast({
                    msg: err.msg,
                    duration: 3000,
                    location: 'bottom'
                });
                }
            })
        },
        //
        getmonthdata:function(val){
            var that = this;
            that.cardsmonth = val;
            that.getdata()
        },
        //
        addfeed:function(type,desc){
            var that = this;
            api.openWin({
                name: 'addrun',
                url: './addrun.html',
                pageParam: {
                    date: that.cardsmonth,
                    type:type,//1新增 2编辑
                    listdesc:desc,//编辑页desc
                }
            });
        },
        imgPer:function(){
          let that =this;
          var resultList = api.hasPermission({
              list:['camera','storage','photos']
          });
          if(!resultList[0].granted || !resultList[1].granted || !resultList[2].granted){
            // 没有权限
            that.reqPer()
          }else{
            // 有权限
            that.openpic()
          }
        },
        // 再请求
        reqPer:function(){
          let that =this;
          // 没有权限
          api.requestPermission({
              list:['camera','storage','photos'],
              code:1
          }, function(ret, err){
              if(ret.list[0].granted && ret.list[1].granted && ret.list[2].granted){
                // 允许
                that.openpic()
              }else{
                // 禁止
                that.noPer()
              }
              // 不再提醒
              if(ret.never){

              }
          });
        },
        // 禁止
        noPer:function(){
          let that =this;
          api.confirm({
            title: '提醒',
            msg: '没有获得 ' + '相机' + " 权限\n是否前往设置？",
            buttons: ['去设置', '取消']
          }, function(ret, err) {
            if(1 == ret.buttonIndex){
              that.reqPer();
            }
          });
        },
        //调起相机
        openpic:function(){
          let that =this;
          api.actionSheet({
              cancelTitle: '取消',
              buttons: ['相机', '相册']
          }, function(ret, err) {
              var tindex = ret.buttonIndex;
              if(tindex==1){//相机
                that.choicepic('camera')
              }else if(tindex==2){//相机
                that.choicepic('album')
              }
          });
        },
        //图片he视频上传
        choicepic:function(type){
          let that =this;
          api.getPicture({
            sourceType: type,
            encodingType: 'jpg',
            mediaValue: 'pic',
            destinationType: 'url',
            allowEdit: true,
            preview:true,
            quality: 50,
            saveToPhotoAlbum: true,
            groupName:'餐众邦'
          }, function(ret, err) {
            api.showProgress();
            if (ret) {
                console.log(JSON.stringify(ret));
                api.ajax({
                    url: baseurl+'upload/oss',
                    method: 'post',
                    data: {
                      values: {
                        "sec":$api.getStorage('apptoken'),
                      },
                      files: {
                        "file": ret.data
                      }
                    }
                }, function(ret, err) {
                  // console.log(JSON.stringify(ret));
                  // console.log(JSON.stringify(err));
                  api.hideProgress();
                  if(ret.status==1){
                    api.hideProgress();
                    // that.uploadvideo(ret.data[0].url)
                    that.input4 = ret.data[0].url;
                    // console.log(that.input4);


                  }else{
                    api.hideProgress();
                    api.toast({
                        msg: '上传失败，请重新选择',
                        duration: 3000,
                        location: 'bottom'
                    });
                  }
                });
            } else {
                api.hideProgress();
                console.log(JSON.stringify(err));
                api.toast({
                    msg: '上传失败，请重新选择',
                    duration: 3000,
                    location: 'bottom'
                });
            }
          });
        },
        //提交图片
        okgettime:function(){
          let that=this;
          api.ajax({
            url:baseurl+'api/guide/setResult',
            methods:'get',
            data:{
              values:{
                sec: $api.getStorage('apptoken'),
                id:that.listid,
                result_str:that.textvalue,
                result_img:that.input4,
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){
                api.alert({
                    title: '提交成功',
                    msg: '',
                }, function(ret, err) {
                  that.edittoast = false;
                  that.getdata()
                });


              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
        
      }
    })
	}


	</script>
</body>
</html>
